const { communityModel } = require('../modules/communityModel');

// 新增
async function addCommunity(req, res, next) {

    const data = req.body;
    console.log(data);
    await communityModel.create(data);
    res.send({
        message: '新增小区成功',
        code: 200,

    })
}

// 查找
async function getCommunity(req, res, next) {
    const { value } = req.query;
    console.log(`前端返回的小区------------------------------`, value);
    const result = await communityModel.find(
        {
            $or: [
                { communityName: { $regex: value, $options: '$i' } },

            ]
        }
    );
    // console.log(result);
    res.send({
        message: '获取小区数据成功',
        code: 200,
        result
    })
}

// 删除
async function deleteCommunity(req, res, next) {
    const _id = req.body;
    await communityModel.deleteOne({ _id });
    res.send({
        message: '删除成功',
        code: 200
    })


}



module.exports = { addCommunity, getCommunity, deleteCommunity }